<?php
/**
 * 
 * @author Administrator
 *
 */
class ActiveRecord extends CActiveRecord {
	/**
	 * 执行find动作，并返回数据数组.
	 * support function for find.
	 *
	 * @param mixed $condition        	
	 * @param array $params        	
	 * @return multitype:
	 */
	public function findToArray($condition = '', $params = array()) {
		$return = $this->find ( $condition, $params );
		return is_array ( $return->attributes ) ? $return->attributes : array ();
	}
	/**
	 * 执行findAll动作，并返回数据数组.
	 * support function for findAll.
	 *
	 * @param mixed $condition        	
	 * @param array $params        	
	 * @return multitype:
	 */
	public function findAllToArray($condition = '', $params = array()) {
		$return = $this->findAll ( $condition, $params );
		$data = array ();
		foreach ( $return as $record ) {
			is_array ( $record->attributes ) && ($data [] = $record->attributes);
		}
		return $data;
	}
	/**
	 * 返回实例的数组数据.
	 *
	 * @return multitype:
	 */
	public function toArray() {
		$return = array ();
		if ($this instanceof CActiveRecord) {
			$return = is_array ( $this->attributes ) ? $this->attributes : array ();
		}
		return $return;
	}
	/**
	 * 将CActiveRecord实例（如find）转化为数组数据返回.
	 * 多个CActiveRecord实例（如findAll）将转换为多维数组.
	 *
	 * @param unknown $model        	
	 * @return multitype:Ambigous <multitype:, multitype:multitype: > |multitype:
	 */
	public static function getArray($model) {
		if (is_array ( $model )) {
			$return = array ();
			foreach ( $model as $m ) {
				$return [] = self::getArray ( $m );
			}
			return $return;
		}
		if ($model instanceof CActiveRecord) {
			return is_array ( $model->attributes ) ? $model->attributes : array ();
		}
		return array ();
	}
}